package com.wenchao.quickstart.utils;

import java.math.BigDecimal;

/**
 * 【类的描述】介绍一下该类的用途
 *
 * @author zhangwenchao
 * @date 2022-01-25
 */
public class DecimalUtils {

    public static String formatDecimal(double old, int length) {
        BigDecimal bigDecimal = new BigDecimal(old);
        return bigDecimal.setScale(length, BigDecimal.ROUND_HALF_UP).toString();
    }

    public static Double formatDecimal2Double(double old, int length) {
        BigDecimal bigDecimal = new BigDecimal(old);
        return bigDecimal.setScale(length, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

}
